[feat] new azure-ai-agentserver-optimization package for load_config#47096
[feat] new azure-ai-agentserver-optimization package for load_config#47096Zyysurely wants to merge 15 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new azure-ai-agentserver-optimization package under sdk/agentserver/ that provides a single load_config() entry point for resolving hosted-agent optimization configuration from multiple sources (env inline JSON, resolver API, local directory, defaults), and wires the new package into the agentserver CI artifact list.
Changes:
- Added the new
azure-ai-agentserver-optimizationpackage (packaging metadata, README, changelog, namespace package files, and typed implementation for config loading + resolver API persistence). - Implemented config resolution logic (
_config.py), models/parsers (_models.py), and remote candidate resolution/persistence (_resolver.py). - Added a comprehensive unit test suite for resolution priorities, parsing, persistence, and resolver behavior; updated
sdk/agentserver/ci.ymlto include the new artifact.
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/agentserver/ci.yml | Adds azure-ai-agentserver-optimization to CI artifacts for the agentserver service directory. |
| sdk/agentserver/azure-ai-agentserver-optimization/README.md | New package README describing load_config(), env vars, file layout, and formats. |
| sdk/agentserver/azure-ai-agentserver-optimization/pyproject.toml | New package build metadata, dependencies, classifiers, and azure-sdk-build settings. |
| sdk/agentserver/azure-ai-agentserver-optimization/MANIFEST.in | sdist manifest entries (docs, license, tests, namespace files, py.typed). |
| sdk/agentserver/azure-ai-agentserver-optimization/LICENSE | MIT license for the new package. |
| sdk/agentserver/azure-ai-agentserver-optimization/dev_requirements.txt | Dev/test requirements for the new package. |
| sdk/agentserver/azure-ai-agentserver-optimization/CHANGELOG.md | Initial release notes for the new package. |
| sdk/agentserver/azure-ai-agentserver-optimization/azure/init.py | Namespace package marker for azure. |
| sdk/agentserver/azure-ai-agentserver-optimization/azure/ai/init.py | Namespace package marker for azure.ai. |
| sdk/agentserver/azure-ai-agentserver-optimization/azure/ai/agentserver/init.py | Namespace package marker for azure.ai.agentserver. |
| sdk/agentserver/azure-ai-agentserver-optimization/azure/ai/agentserver/optimization/init.py | Public API exports (load_config, models) and module docstring. |
| sdk/agentserver/azure-ai-agentserver-optimization/azure/ai/agentserver/optimization/_version.py | Declares package version. |
| sdk/agentserver/azure-ai-agentserver-optimization/azure/ai/agentserver/optimization/_models.py | Dataclasses (OptimizationConfig, etc.) and parsing helpers. |
| sdk/agentserver/azure-ai-agentserver-optimization/azure/ai/agentserver/optimization/_config.py | load_config() implementation + local directory loading/parsing. |
| sdk/agentserver/azure-ai-agentserver-optimization/azure/ai/agentserver/optimization/_resolver.py | Remote resolver API calls and persistence to local layout. |
| sdk/agentserver/azure-ai-agentserver-optimization/azure/ai/agentserver/optimization/py.typed | Enables PEP 561 typing for the package. |
| sdk/agentserver/azure-ai-agentserver-optimization/tests/conftest.py | Test-wide env var cleanup fixture. |
| sdk/agentserver/azure-ai-agentserver-optimization/tests/test_config.py | Unit tests for load_config() resolution and parsing helpers. |
| sdk/agentserver/azure-ai-agentserver-optimization/tests/test_resolver.py | Unit tests for resolver API behavior and persistence helpers. |
…solution Enable single-version candidate resolution by accepting candidate_id as a parameter (e.g. from the X-Optimization-Candidate-Id request header) instead of requiring an env var per deployed version. The parameter takes precedence over the OPTIMIZATION_CANDIDATE_ID env var and is threaded through to both the resolver API and local directory lookup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
load_config() now automatically reads the candidate ID from the X-Optimization-Candidate-Id request header (Flask/Quart) when no explicit candidate_id parameter is passed. Resolution order: 1. Explicit candidate_id param 2. X-Optimization-Candidate-Id request header (auto-detected) 3. OPTIMIZATION_CANDIDATE_ID env var Also exports OPTIMIZATION_CANDIDATE_HEADER constant for agents that need to reference the header name. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # --------------------------------------------------------- | ||
|
|
||
| """Agent Optimization — Config loader for optimization-ready hosted agents. |
There was a problem hiding this comment.
Is there a better (or maybe more specific) name for this than "config"? While this is config:ish, configuration generally goes beyond the prompts/descriptions etc. and chances are that there is actual additional configuration elsewhere in the agent implementation.
There was a problem hiding this comment.
Currently, we can't change it now since it's already documented in our public docs (merged yesterday), probably we can introduce any more function/rename later with backward compatible,
| try: | ||
| from azure.identity import DefaultAzureCredential | ||
|
|
||
| credential = DefaultAzureCredential() |
There was a problem hiding this comment.
Don't directly instantiate DefaultAzureCredential in a library. There are corner cases where this can lead to unexpected credentials being picked up.
There was a problem hiding this comment.
User can pass credential in now, but since it's mainly for hosted agent, so we still fallback to default credential which is using agent identity.
There was a problem hiding this comment.
We should at least fall back to the specific identity and not the full credential chain if that is the case. The security team/review is pushing harder and harder on this.
…-only on persist - Move DefaultAzureCredential and sys imports to module top-level - Remove PyYAML ImportError fallback (formal dependency) - Make metadata.yaml parse errors raise ValueError - Extract _fetch_candidate_config() helper from resolve_candidate() - Raise ValueError on config fetch, manifest fetch, and skill download failures - Keep persist-to-disk failures as warnings (non-fatal) - Skip skill download when persist fails (try/except/else pattern) - Remove pydantic dependency from all test files (plain Python stubs) - Update tests to match fail-fast semantics (pytest.raises for ValueError) - Add tests for _fetch_candidate_config and download exception cases - Fix DefaultAzureCredential mock patch path in TestBuildClient
Description
azure-ai-agentserver-optimization— Initial beta release (1.0.0b1)Summary
Adds a new package
azure-ai-agentserver-optimizationthat provides a drop-in config loader for optimization-ready Azure AI Hosted Agents. A singleload_config()call resolves optimization parameters (instructions, model, temperature, skills, tool definitions) from multiple sources with graceful fallback — the agent works unchanged when not running under optimization.What's included
Public API:
load_config(*, config_dir, required)— 4-priority config resolution with graceful fallbackload_skills_from_dir(path)— load skills from a directory ofSKILL.mdfiles on demandOptimizationConfig— resolved config dataclass (instructions, model, temperature, skills, skills_dir, tool_definitions, source, candidate_id)OptimizationConfig.apply_tool_descriptions(tools)— patch__doc__,.description, andinput_modelparameter descriptions on @tool-decorated functionsOptimizationConfig.compose_instructions()— append skill catalog to instructionsCandidateConfig/Skill— typed models for API payload and learned skillsResolution order (first match wins):
OPTIMIZATION_CONFIGenv var (used by temp agent versions during eval)OPTIMIZATION_CANDIDATE_ID+OPTIMIZATION_RESOLVE_ENDPOINT→ fetches config, persists to local layoutconfig_dirparam /OPTIMIZATION_LOCAL_DIRenv var /.agent_configs/default → readsmetadata.yaml+instructions.md+tools.json+skills/required=TrueraisesValueError;required=FalsereturnsNoneKey design decisions:
baseline/as required fallback,<candidate_id>/folders for optimization candidatesazure-corePipelineClientfor HTTP transport withDefaultAzureCredentialauthFiles
azure/ai/agentserver/optimization/_config.py— config loader with 4-priority resolutionazure/ai/agentserver/optimization/_models.py— data models (OptimizationConfig, CandidateConfig, Skill, MetadataConfig)azure/ai/agentserver/optimization/_resolver.py— resolver API client with local persistencetests/test_config.py,test_resolver.py,test_integration.py— 183 tests